package myjava.IO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Serialization {

   public static void main(String[] args) {

      Foo person = new Foo("Laurent");
      
      try {
         FileOutputStream fos = new FileOutputStream("serialization.txt");
         ObjectOutputStream oos = new ObjectOutputStream(fos);
         oos.writeObject(person);
         oos.writeBoolean(true);
         oos.close();
         FileInputStream fis = new FileInputStream("serialization.txt");
         ObjectInputStream ois = new ObjectInputStream(fis);
         Foo person2 = (Foo) ois.readObject();
         boolean goodAtJava = (boolean) ois.readBoolean();
         ois.close();
         System.out.println(person2.getName());
         System.out.println("good at java: " + goodAtJava);
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

class Foo implements Serializable {

   String name;

   Foo(String n) {
      name = n;
   }
   String getName() {
      return name;
   }
}